#import "dfhgwhruebvhrheysternideology.h"
#import "dfhgwhruebvhrheyavenuetyre.h"
#import "dfhgwhruebvhrheyluggagerecorder.h"
#import "dfhgwhruebvhrheysavingmuscular.h"
#import "dfhgwhruebvhrheyarrestmeans.h"
#import "dfhgwhruebvhrheycurvereciprocalViewController.h"
#import "dfhgwhruebvhrheyversionvictimViewController.h"
@interface dfhgwhruebvhrheyversionvictimViewController ()
@end
static NSString *cache_img_prefix = @"option_auth_";
@implementation dfhgwhruebvhrheyversionvictimViewController {
	UILabel *jobText;
	UIButton *jobBtn1;
	UIButton *jobBtn2;
	UILabel *jobBottomText1;
	UILabel *jobBottomText2;
	UILabel *jobBottomTips;
	UIView *line1;
	UILabel *businessText;
	UIButton *businessBtn1;
	UIButton *businessBtn2;
	UILabel *businessBottomText1;
	UILabel *businessBottomText2;
	UILabel *businessBottomTips;
	UIView *line2;
	UILabel *repaymentText;
	UIButton *repaymentBtn1;
	UIButton *repaymentBtn2;
	UILabel *repaymentBottomText1;
	UILabel *repaymentBottomText2;
	UILabel *repaymentBottomTips;
	UIButton *confirmBtn;
}
- (UILabel *)generateLabelWithText:(NSString *)text andFont:(UIFont *)font andTextColor:(UIColor *)color {
	UILabel *lb = [[UILabel alloc] init];
	lb.font = font;
	lb.text = text;
	lb.textColor = color;
	return lb;
}
- (UIButton *)generatePicButton {
	UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
	btn.backgroundColor = @"#F5F6F9".dhgfywegwygeydwlearneddesignate;
	[btn setImage:[UIImage imageNamed:@"dhgfywegwygeydwassemblepursuit"] forState:UIControlStateNormal];
	[btn addTarget:self action:@selector(extraBtnAction:) forControlEvents:UIControlEventTouchUpInside];
	return btn;
}
- (void)viewDidLoad {
    [super viewDidLoad];
	[self loadUI];
	[dfhgwhruebvhrheyoptionsaving uploadRiskDataByCatchId:@"10" andApplyId:nil withDetailId:nil];
	[dfhgwhruebvhrheyavenuetyre addTracking:upload_attachment withValue:0 byType:3];
	[dfhgwhruebvhrheyavenuetyre addTracking:page_duration_option withValue:0 byType:3];
}
- (void)loadUI {
	self.backgroundColor = [UIColor whiteColor];
	[self configBackIcon:@"dhgfywegwygeydwcurvereciprocal"];
	self.navigationItem.title = @"References";
	self.navigationStyle = dhgfywegwygeydwreciprocaltransport;
	jobText = [self generateLabelWithText:@"Job Information（Optional）" andFont:[UIFont medium:16] andTextColor:primary_color.dhgfywegwygeydwlearneddesignate];
	[self.containerView addSubview:jobText];
	jobBtn1 = [self generatePicButton];
	jobBtn1.tag = 100;
	NSString *job1String = [dfhgwhruebvhrheyoptionsaving getDataStringByKey:[NSString stringWithFormat:@"%@%ld.data" , cache_img_prefix,jobBtn1.tag]];
	if(job1String.length) {
		NSData *jobBtn1ImgData = [[NSData alloc] initWithBase64EncodedString:job1String options: NSDataBase64DecodingIgnoreUnknownCharacters];
		[jobBtn1 setImage:[UIImage imageWithData:jobBtn1ImgData] forState:UIControlStateNormal];
	}
	[self.containerView addSubview:jobBtn1];
	jobBtn2 = [self generatePicButton];
	jobBtn2.tag = 101;
	NSString *job2String = [dfhgwhruebvhrheyoptionsaving getDataStringByKey:[NSString stringWithFormat:@"%@%ld.data" , cache_img_prefix,jobBtn2.tag]];
	if(job2String.length) {
		NSData *jobBtn2ImgData = [[NSData alloc] initWithBase64EncodedString:job1String options: NSDataBase64DecodingIgnoreUnknownCharacters];
		[jobBtn2 setImage:[UIImage imageWithData:jobBtn2ImgData] forState:UIControlStateNormal];
	}
	[self.containerView addSubview:jobBtn2];
	jobBottomText1 = [self generateLabelWithText:@"Employee’s Card or Payslip" andFont:[UIFont regular:12] andTextColor:@"#3B414B".dhgfywegwygeydwlearneddesignate];
	jobBottomText1.textAlignment = NSTextAlignmentCenter;
	[self.containerView addSubview:jobBottomText1];
	jobBottomText2 = [self generateLabelWithText:@"Other work photo" andFont:[UIFont regular:12] andTextColor:@"#3B414B".dhgfywegwygeydwlearneddesignate];
	jobBottomText2.textAlignment = NSTextAlignmentCenter;
	[self.containerView addSubview:jobBottomText2];
	jobBottomTips = [self generateLabelWithText:@"Upload any photo can prove your work in this company,such as ATM Card、Receipt of Biling or Remittances etc." andFont:[UIFont regular:12] andTextColor:@"#A6AAB4".dhgfywegwygeydwlearneddesignate];
	jobBottomTips.numberOfLines = 0;
	[self.containerView addSubview:jobBottomTips];
	line1 = [[UIView alloc] init];
	line1.backgroundColor = @"#E6E6E6".dhgfywegwygeydwlearneddesignate;
	[self.containerView addSubview:line1];
	businessText = [self generateLabelWithText:@"Business Information（Optional）" andFont:[UIFont medium:16] andTextColor:primary_color.dhgfywegwygeydwlearneddesignate];
	[self.containerView addSubview:businessText];
	businessBtn1 = [self generatePicButton];
	businessBtn1.tag = 102;
	NSString *business1String = [dfhgwhruebvhrheyoptionsaving getDataStringByKey:[NSString stringWithFormat:@"%@%ld.data" , cache_img_prefix,businessBtn1.tag]];
	if(business1String.length) {
		NSData *businessBtn1ImgData = [[NSData alloc] initWithBase64EncodedString:business1String options: NSDataBase64DecodingIgnoreUnknownCharacters];
		[businessBtn1 setImage:[UIImage imageWithData:businessBtn1ImgData] forState:UIControlStateNormal];
	}
	[self.containerView addSubview:businessBtn1];
	businessBtn2 = [self generatePicButton];
	businessBtn2.tag = 103;
	NSString *business2String = [dfhgwhruebvhrheyoptionsaving getDataStringByKey:[NSString stringWithFormat:@"%@%ld.data" , cache_img_prefix,businessBtn2.tag]];
	if(business2String.length) {
		NSData *businessBtn2ImgData = [[NSData alloc] initWithBase64EncodedString:business2String options: NSDataBase64DecodingIgnoreUnknownCharacters];
		[businessBtn2 setImage:[UIImage imageWithData:businessBtn2ImgData] forState:UIControlStateNormal];
	}
	[self.containerView addSubview:businessBtn2];
	businessBottomText1 = [self generateLabelWithText:@"Bussiness Permit" andFont:[UIFont regular:12] andTextColor:@"#3B414B".dhgfywegwygeydwlearneddesignate];
	businessBottomText1.textAlignment = NSTextAlignmentCenter;
	[self.containerView addSubview:businessBottomText1];
	businessBottomText2 = [self generateLabelWithText:@"Other business information" andFont:[UIFont regular:12] andTextColor:@"#3B414B".dhgfywegwygeydwlearneddesignate];
	businessBottomText2.textAlignment = NSTextAlignmentCenter;
	[self.containerView addSubview:businessBottomText2];
	businessBottomTips = [self generateLabelWithText:@"Upload any photo prove that you own the business,such as Bussiness Permit、Brgy Clearance etc." andFont:[UIFont regular:12] andTextColor:@"#A6AAB4".dhgfywegwygeydwlearneddesignate];
	businessBottomTips.numberOfLines = 0;
	[self.containerView addSubview:businessBottomTips];
	line2 = [[UIView alloc] init];
	line2.backgroundColor = @"#E6E6E6".dhgfywegwygeydwlearneddesignate;
	[self.containerView addSubview:line2];
	repaymentText = [self generateLabelWithText:@"Repayment Vouchers of Other Platforms（Optional）" andFont:[UIFont medium:16] andTextColor:primary_color.dhgfywegwygeydwlearneddesignate];
	repaymentText.numberOfLines = 0;
	[self.containerView addSubview:repaymentText];
	repaymentBtn1 = [self generatePicButton];
	repaymentBtn1.tag = 104;
	NSString *repayment1String = [dfhgwhruebvhrheyoptionsaving getDataStringByKey:[NSString stringWithFormat:@"%@%ld.data" , cache_img_prefix,repaymentBtn1.tag]];
	if(repayment1String.length) {
		NSData *repaymentBtn1ImgData = [[NSData alloc] initWithBase64EncodedString:repayment1String options: NSDataBase64DecodingIgnoreUnknownCharacters];
		[repaymentBtn1 setImage:[UIImage imageWithData:repaymentBtn1ImgData] forState:UIControlStateNormal];
	}
	[self.containerView addSubview:repaymentBtn1];
	repaymentBtn2 = [self generatePicButton];
	repaymentBtn2.tag = 105;
	NSString *repayment2String = [dfhgwhruebvhrheyoptionsaving getDataStringByKey:[NSString stringWithFormat:@"%@%ld.data" , cache_img_prefix,repaymentBtn2.tag]];
	if(repayment2String.length) {
		NSData *repaymentBtn2ImgData = [[NSData alloc] initWithBase64EncodedString:repayment2String options: NSDataBase64DecodingIgnoreUnknownCharacters];
		[repaymentBtn2 setImage:[UIImage imageWithData:repaymentBtn2ImgData] forState:UIControlStateNormal];
	}
	[self.containerView addSubview:repaymentBtn2];
	repaymentBottomText1 = [self generateLabelWithText:@"Repayment Vouchers" andFont:[UIFont regular:12] andTextColor:@"#3B414B".dhgfywegwygeydwlearneddesignate];
	repaymentBottomText1.textAlignment = NSTextAlignmentCenter;
	[self.containerView addSubview:repaymentBottomText1];
	repaymentBottomText2 = [self generateLabelWithText:@"Add more" andFont:[UIFont regular:12] andTextColor:@"#3B414B".dhgfywegwygeydwlearneddesignate];
	repaymentBottomText2.textAlignment = NSTextAlignmentCenter;
	[self.containerView addSubview:repaymentBottomText2];
	repaymentBottomTips = [self generateLabelWithText:@"Tips:Please ensure picture of documents are taken clearly and newest in order to get the loan instantly" andFont:[UIFont regular:12] andTextColor:@"#A6AAB4".dhgfywegwygeydwlearneddesignate];
	repaymentBottomTips.numberOfLines = 0;
	[self.containerView addSubview:repaymentBottomTips];
	confirmBtn = [UIButton buttonWithType:UIButtonTypeCustom];
	confirmBtn.layer.cornerRadius = 10;
	confirmBtn.backgroundColor = primary_color.dhgfywegwygeydwlearneddesignate;
	confirmBtn.titleLabel.font = [UIFont semiBold:18];
	[confirmBtn setTitle:@"Continue" forState:UIControlStateNormal];
	[confirmBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
	[self.containerView addSubview:confirmBtn];
	[confirmBtn addTarget:self action:@selector(confirmBtnAction) forControlEvents:UIControlEventTouchUpInside];
}
- (void)startUpload:(NSString *)fileName withType:(NSInteger)type {
	NSMutableDictionary *params = [NSMutableDictionary dictionary];
	params[@"photo_name"] = fileName;
	params[@"type"] = @(type);
	[[dfhgwhruebvhrheyluggagerecorder shareInstance] dhgfywegwygeydwbarrierawait:dhgfywegwygeydwawaitlamb path:optionAuthPicLoadApi isEncrypt:YES withParams:params success:^(NSURLSessionDataTask * _Nonnull task, NSString * _Nonnull json) {
		dfhgwhruebvhrheysternideology *model = [dfhgwhruebvhrheysternideology yy_modelWithJSON:json];
		if (model.code == 200) {
			[dfhgwhruebvhrheyoptionsaving.keyWindow show:@"Success"];
		}else {
			[dfhgwhruebvhrheyoptionsaving.keyWindow show:model.error];
		}
	} failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
		NSLog(@"=== %@", error);
	}];
}
- (void)uploadPic:(UIImage *)pic withSender:(UIButton *)sender {
	NSInteger type = sender.tag - 97;
	[dfhgwhruebvhrheyoptionsaving.keyWindow startLoading];
	[dfhgwhruebvhrheysavingmuscular uploadImage:pic withType:type andResult:^(BOOL completion, NSString * _Nonnull name, long long size) {
		if(completion) {
			dispatch_async(dispatch_get_main_queue(), ^{
				[dfhgwhruebvhrheyoptionsaving.keyWindow stopLoading];
				[self startUpload:name withType:type];
				[sender setImage:pic forState:UIControlStateNormal];
				NSString *dataString = [UIImagePNGRepresentation(pic) base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
				[dfhgwhruebvhrheyoptionsaving saveDataString:dataString withKey:[NSString stringWithFormat:@"%@%ld.data" , cache_img_prefix,sender.tag]];
			});
		}
	}];
	switch (sender.tag) {
		case 100: {
			[dfhgwhruebvhrheyavenuetyre duartion:employee_card_payslip_duration isCover:YES byType:3];
		}
			break;
		case 101: {
			[dfhgwhruebvhrheyavenuetyre duartion:other_work_photo_duration isCover:YES byType:3];
		}
			break;
		case 102: {
			[dfhgwhruebvhrheyavenuetyre duartion:business_permit_duration isCover:YES byType:3];
		}
			break;
		case 103: {
			[dfhgwhruebvhrheyavenuetyre duartion:other_business_duration isCover:YES byType:3];
		}
			break;
		case 104: {
			[dfhgwhruebvhrheyavenuetyre duartion:repayment_vouchers_duraion isCover:YES byType:3];
		}
			break;
		case 105: {
			[dfhgwhruebvhrheyavenuetyre duartion:add_more_duration isCover:YES byType:3];
		}
			break;
		default:
			break;
	}
}
- (void)extraBtnAction:(UIButton *)sender {
	__weak typeof(self) weakSelf = self;
	dfhgwhruebvhrheycurvereciprocalViewController *cameraVC = [[dfhgwhruebvhrheycurvereciprocalViewController alloc] init];
	cameraVC.tipsString = @"Please put what you want to take a picture into the box";
	dfhgwhruebvhrheyarrestmeans *navVC = [[dfhgwhruebvhrheyarrestmeans alloc] initWithRootViewController:cameraVC];
	navVC.modalPresentationStyle = UIModalPresentationFullScreen;
	[self presentViewController:navVC animated:YES completion:nil];
	[cameraVC cameraFinish:^(UIImage * _Nonnull photo) {
		__strong typeof(weakSelf) strongSelf = weakSelf;
		[strongSelf uploadPic:photo withSender:sender];
	}];
	switch (sender.tag) {
		case 100: {
			[dfhgwhruebvhrheyavenuetyre addTracking:employee_card_payslip_duration withValue:0 byType:3];
			[dfhgwhruebvhrheyavenuetyre updateCount:employee_card_payslip_updatecount byType:3];
		}
			break;
		case 101: {
			[dfhgwhruebvhrheyavenuetyre addTracking:other_work_photo_duration withValue:0 byType:3];
			[dfhgwhruebvhrheyavenuetyre updateCount:other_work_photo_updatecount byType:3];
		}
			break;
		case 102: {
			[dfhgwhruebvhrheyavenuetyre addTracking:business_permit_duration withValue:0 byType:3];
			[dfhgwhruebvhrheyavenuetyre updateCount:business_permit_updatecount byType:3];
		}
			break;
		case 103: {
			[dfhgwhruebvhrheyavenuetyre addTracking:other_business_duration withValue:0 byType:3];
			[dfhgwhruebvhrheyavenuetyre updateCount:other_business_updatecount byType:3];
		}
			break;
		case 104: {
			[dfhgwhruebvhrheyavenuetyre addTracking:repayment_vouchers_duraion withValue:0 byType:3];
			[dfhgwhruebvhrheyavenuetyre updateCount:repayment_vouchers_updatecount byType:3];
		}
			break;
		case 105: {
			[dfhgwhruebvhrheyavenuetyre addTracking:add_more_duration withValue:0 byType:3];
			[dfhgwhruebvhrheyavenuetyre updateCount:add_more_updatecount byType:3];
		}
			break;
		default:
			break;
	}
}
- (void)backAction {
	[self.navigationController popViewControllerAnimated:YES];
}
- (void)confirmBtnAction {
	[self.navigationController popViewControllerAnimated:YES];
	[dfhgwhruebvhrheyavenuetyre duartion:page_duration_option isCover:YES byType:3];
	[dfhgwhruebvhrheyavenuetyre addTracking:next_time withValue:0 byType:3];
	[dfhgwhruebvhrheyavenuetyre uploadRiskingData:3];
}
- (void)viewDidLayoutSubviews {
	[super viewDidLayoutSubviews];
	[jobText mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(self.containerView).offset(15);
		make.left.equalTo(self.containerView).offset(13);
		make.height.mas_equalTo(23);
	}];
	[jobBtn1 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(jobText);
		make.width.equalTo(jobBtn2);
		make.height.mas_equalTo(100);
		make.top.equalTo(jobText.mas_bottom).offset(14);
	}];
	[jobBtn2 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.right.equalTo(self.containerView).offset(-13);
		make.left.equalTo(jobBtn1.mas_right).offset(29);
		make.centerY.height.equalTo(jobBtn1);
	}];
	[jobBottomText1 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.width.equalTo(jobBtn1);
		make.height.mas_equalTo(17);
		make.top.equalTo(jobBtn1.mas_bottom).offset(10);
	}];
	[jobBottomText2 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.width.equalTo(jobBtn2);
		make.height.mas_equalTo(17);
		make.top.equalTo(jobBtn2.mas_bottom).offset(10);
	}];
	[jobBottomTips mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(jobBottomText1.mas_bottom).offset(12);
		make.centerX.equalTo(self.containerView);
		make.left.equalTo(jobBottomText1);
		make.height.mas_equalTo(51);
	}];
	[line1 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(jobBottomTips.mas_bottom).offset(15);
		make.left.right.equalTo(jobBottomTips);
		make.height.mas_equalTo(1);
	}];
	[businessText mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(line1.mas_bottom).offset(15);
		make.left.equalTo(self.containerView).offset(13);
		make.height.mas_equalTo(23);
	}];
	[businessBtn1 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(businessText);
		make.width.equalTo(businessBtn2);
		make.height.mas_equalTo(100);
		make.top.equalTo(businessText.mas_bottom).offset(14);
	}];
	[businessBtn2 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.right.equalTo(self.containerView).offset(-13);
		make.left.equalTo(businessBtn1.mas_right).offset(29);
		make.centerY.height.equalTo(businessBtn1);
	}];
	[businessBottomText1 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.width.equalTo(businessBtn1);
		make.height.mas_equalTo(17);
		make.top.equalTo(businessBtn1.mas_bottom).offset(10);
	}];
	[businessBottomText2 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.width.equalTo(businessBtn2);
		make.height.mas_equalTo(17);
		make.top.equalTo(businessBtn2.mas_bottom).offset(10);
	}];
	[businessBottomTips mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(businessBottomText1.mas_bottom).offset(12);
		make.centerX.equalTo(self.containerView);
		make.left.equalTo(businessBottomText1);
		make.height.mas_equalTo(51);
	}];
	[line2 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(businessBottomTips.mas_bottom).offset(15);
		make.left.right.equalTo(businessBottomTips);
		make.height.mas_equalTo(1);
	}];
	[repaymentText mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.containerView).offset(13);
		make.top.equalTo(line2.mas_bottom).offset(15);
		make.centerX.equalTo(self.containerView);
		make.height.mas_equalTo(46);
	}];
	[repaymentBtn1 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(repaymentText);
		make.width.equalTo(repaymentBtn2);
		make.height.mas_equalTo(100);
		make.top.equalTo(repaymentText.mas_bottom).offset(14);
	}];
	[repaymentBtn2 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.right.equalTo(self.containerView).offset(-13);
		make.left.equalTo(repaymentBtn1.mas_right).offset(29);
		make.centerY.height.equalTo(repaymentBtn1);
	}];
	[repaymentBottomText1 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.width.equalTo(repaymentBtn1);
		make.height.mas_equalTo(17);
		make.top.equalTo(repaymentBtn1.mas_bottom).offset(10);
	}];
	[repaymentBottomText2 mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.width.equalTo(repaymentBtn2);
		make.height.mas_equalTo(17);
		make.top.equalTo(repaymentBtn2.mas_bottom).offset(10);
	}];
	[repaymentBottomTips mas_makeConstraints:^(MASConstraintMaker *make) {
		make.top.equalTo(repaymentBottomText1.mas_bottom).offset(12);
		make.centerX.equalTo(self.containerView);
		make.left.equalTo(repaymentBottomText1);
		make.height.mas_equalTo(51);
	}];
	[confirmBtn mas_makeConstraints:^(MASConstraintMaker *make) {
		make.left.equalTo(self.containerView).offset(13);
		make.height.mas_equalTo(50);
		make.centerX.equalTo(self.containerView);
		make.top.equalTo(repaymentBottomTips.mas_bottom).offset(48);
		make.bottom.equalTo(self.containerView).offset(-30);
	}];
}
@end
